home *** CD-ROM | disk | FTP | other *** search
-
- /**************************************************************************
- * *
- * This code is developed by Adam Li. This software is an *
- * implementation of a part of one or more MPEG-4 Video tools as *
- * specified in ISO/IEC 14496-2 standard. Those intending to use this *
- * software module in hardware or software products are advised that its *
- * use may infringe existing patents or copyrights, and any such use *
- * would be at such party's own risk. The original developer of this *
- * software module and his/her company, and subsequent editors and their *
- * companies (including Project Mayo), will have no liability for use of *
- * this software or modifications or derivatives thereof. *
- * *
- * Project Mayo gives users of the Codec a license to this software *
- * module or modifications thereof for use in hardware or software *
- * products claiming conformance to the MPEG-4 Video Standard as *
- * described in the Open DivX license. *
- * *
- * The complete Open DivX license can be found at *
- * http://www.projectmayo.com/opendivx/license.php . *
- * *
- **************************************************************************/
-
- /*************************************************************************
- *
- * Maintenance.cpp, Maintenance functions
- *
- * Copyright (C) 2000 DivX Networks
- *
- * Adam Li
- * Andrea Graziani
- *
- * DivX Advance Research Center <darc@projectmayo.com>
- *
- ************************************************************************/
-
- // This includes the maintance functions of the driver. There are functions
- // that answers the various info query messages, and configuration of
- // the codec.
-
- #include "stdafx.h"
- #include "codec.h"
- #include "resource.h"
- #include "config_dialog.h"
-
- codec::codec()
- {
- }
-
- codec::~codec()
- {
- }
-
- long codec::getInfo(LPARAM lParam1, LPARAM lParam2)
- {
- ICINFO *info = (ICINFO *)lParam1;
-
- info->fccType = ICTYPE_VIDEO;
- info->fccHandler = mmioFOURCC('D', 'I', 'V', 'X');
- info->dwFlags =
- VIDCF_FASTTEMPORALC | VIDCF_FASTTEMPORALD;
- info->dwVersion = 0;
- info->dwVersionICM = ICVERSION;
- wcscpy(info->szName, L"DivX codec");
- wcscpy(info->szDescription, L"DivX MPEG-4 Codec (Alpha 4.8)");
-
- return lParam2;
- }
-
- long codec::about(LPARAM lParam1, LPARAM lParam2)
- {
- if (lParam1 == -1) return ICERR_OK;
- CDialog dlgAbout(IDD_DIALOG_ABOUT, NULL/*&wndParent*/);
- dlgAbout.DoModal();
- return ICERR_OK;
- }
-
- long codec::config(LPARAM lParam1, LPARAM lParam2)
- {
- if (lParam1 == -1) return ICERR_OK;
- // CDialog dlgConfig(IDD_DIALOG_CONFIG, NULL/*&wndParent*/);
- ConfigDialog dlgConfig(NULL/*&wndParent*/);
- dlgConfig.m_bitrate = bitrate / 1000;
- dlgConfig.m_rc_period = rc_period;
- dlgConfig.m_max_quant = max_quantizer;
- dlgConfig.m_min_quant = min_quantizer;
- dlgConfig.m_search_range.Format("%d", search_range);
- if (dlgConfig.DoModal() == IDOK) {
- bitrate = dlgConfig.m_bitrate * 1000;
- rc_period = dlgConfig.m_rc_period;
- max_quantizer = dlgConfig.m_max_quant;
- min_quantizer = dlgConfig.m_min_quant;
- search_range = atoi(dlgConfig.m_search_range);
- }
-
- return ICERR_OK;
- }
-
- long codec::encGetFormat(LPARAM lParam1, LPARAM lParam2)
- {
- BITMAPINFO *lpbiInput, *lpbiOutput;
- BITMAPV4HEADER *infohdr;
- long x_dim, y_dim;
-
- lpbiInput = (BITMAPINFO *)lParam1;
- lpbiOutput = (BITMAPINFO *)lParam2;
-
- if (lpbiOutput == NULL) return(sizeof(BITMAPV4HEADER) + sizeof(RGBQUAD));
-
- // everything is copied from the input, including the dimensions
- *lpbiOutput = *lpbiInput;
- infohdr = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
- x_dim = infohdr->bV4Width;
- y_dim = infohdr->bV4Height;
-
- infohdr->bV4BitCount = 0;
- infohdr->bV4V4Compression = FOURCC_DIVX;
- infohdr->bV4SizeImage = x_dim * y_dim * 3 / 2 * sizeof(short int);
- return(ICERR_OK);
- }
-
- long codec::encGetSize(LPARAM lParam1, LPARAM lParam2)
- {
- BITMAPINFO *lpbiInput, *lpbiOutput;
- BITMAPV4HEADER *infohdr;
- long x_dim, y_dim;
-
- lpbiInput = (BITMAPINFO *)lParam1;
- lpbiOutput = (BITMAPINFO *)lParam2;
-
- infohdr = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
- x_dim = infohdr->bV4Width;
- y_dim = infohdr->bV4Height;
-
- return(x_dim * y_dim * 3 / 2 * sizeof(short int));
- }
-
- long codec::encQuery(LPARAM lParam1, LPARAM lParam2)
- {
- BITMAPINFO *lpbiInput, *lpbiOutput;
- BITMAPV4HEADER *infohdr_i, *infohdr_o;
- long x_dim_i, y_dim_i, x_dim_o, y_dim_o;
-
- lpbiInput = (BITMAPINFO *)lParam1;
- lpbiOutput = (BITMAPINFO *)lParam2;
-
- infohdr_i = (BITMAPV4HEADER *)&(lpbiInput->bmiHeader);
- x_dim_i = infohdr_i->bV4Width;
- y_dim_i = infohdr_i->bV4Height;
-
- // input dimension has to be divicable by 16
- if ((x_dim_i % 16) || (y_dim_i % 16)) return (ICERR_BADFORMAT);
- // input format has to be un-compressed 24-bit RGB
- // if ((infohdr_i->bV4V4Compression != BI_RGB)
- // || (infohdr_i->bV4BitCount != 24)) return (ICERR_BADFORMAT);
- if (getImageType(infohdr_i) == 0) return (ICERR_BADFORMAT);
-
- if (lpbiOutput == NULL) return (ICERR_OK);
-
- infohdr_o = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
- x_dim_o = infohdr_o->bV4Width;
- y_dim_o = infohdr_o->bV4Height;
-
- // output dimension must be exactly same as the input dimension
- if ((x_dim_o != x_dim_i) || (y_dim_o != y_dim_i)) return (ICERR_BADFORMAT);
- // output format must be DivX with BitCount 0
- if ((infohdr_o->bV4V4Compression != FOURCC_DIVX)
- || (infohdr_o->bV4BitCount != 0)) return (ICERR_BADFORMAT);
-
- return(ICERR_OK);
- }
-
- long codec::encFramesInfo(LPARAM lParam1, LPARAM lParam2)
- {
- ICCOMPRESSFRAMES *icf;
- long icfSize;
-
- icf = (ICCOMPRESSFRAMES *)lParam1;
- icfSize = (long)lParam2;
-
- framerate = (float)icf->dwRate / (float)icf->dwScale;
-
- return(ICERR_OK);
- }
-
- long codec::decGetFormat(LPARAM lParam1, LPARAM lParam2)
- {
- BITMAPINFO *lpbiInput, *lpbiOutput;
- BITMAPV4HEADER *infohdr;
- long x_dim, y_dim;
-
- lpbiInput = (BITMAPINFO *)lParam1;
- lpbiOutput = (BITMAPINFO *)lParam2;
-
- if (lpbiOutput == 0)
- return (sizeof(BITMAPV4HEADER) + sizeof(RGBQUAD));
-
- // everything is copied from the input, including the dimensions
- *lpbiOutput = *lpbiInput;
- infohdr = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
- x_dim = infohdr->bV4Width;
- y_dim = infohdr->bV4Height;
-
- infohdr->bV4BitCount = 24;
- infohdr->bV4V4Compression = BI_RGB;
- infohdr->bV4SizeImage = x_dim * y_dim * 3;
-
- return ICERR_OK;
- }
-
- long codec::decQuery(LPARAM lParam1, LPARAM lParam2)
- {
- BITMAPINFO *lpbiInput, *lpbiOutput;
- BITMAPV4HEADER *infohdr_i, *infohdr_o;
- long x_dim_i, y_dim_i, x_dim_o, y_dim_o;
-
- lpbiInput = (BITMAPINFO *)lParam1;
- lpbiOutput = (BITMAPINFO *)lParam2;
-
- infohdr_i = (BITMAPV4HEADER *)&(lpbiInput->bmiHeader);
- x_dim_i = infohdr_i->bV4Width;
- y_dim_i = infohdr_i->bV4Height;
-
- // input supported features
- if ((x_dim_i % 16) || (y_dim_i % 16))
- return ICERR_BADFORMAT; // input dimension has to be divicable by 16
- if (!((infohdr_i->bV4V4Compression == FOURCC_DIVX) || (infohdr_i->bV4V4Compression == 4L /* BI_JPEG */))
- || (infohdr_i->bV4BitCount != 0))
- return ICERR_BADFORMAT; // input format must be DivX with BitCount 0
-
- if (lpbiOutput == NULL)
- return ICERR_OK;
-
- infohdr_o = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
- x_dim_o = infohdr_o->bV4Width;
- y_dim_o = infohdr_o->bV4Height;
-
- // output supported features
- if ((x_dim_o != x_dim_i) || (y_dim_o != y_dim_i))
- return ICERR_BADFORMAT; // output dimension must be exactly same as the input dimension
- if (infohdr_o->bV4V4Compression != BI_RGB)
- return ICERR_BADFORMAT; // output format has to be uncompressed
- if ((infohdr_o->bV4BitCount < 16) || (infohdr_o->bV4BitCount > 32))
- return ICERR_BADFORMAT;
-
- return ICERR_OK;
- }
-
-